*************************************************
* Purpose -- Event study analysis using QCEW
* data
************************************************
clear all
* RUN 00_path_master.do FIRST TO GET FILEPATHS


**************************************************************************
* Part 1: Create different frames for analysis
**************************************************************************


/* This is a large do file, so if you want to just replicate particular 
exhibits, you should run Part 1 of the code, so that you have all frames
saved, and then in Part 2, you can just jump to the relevant portion and run
that */

************************************************
* Loading different samples
************************************************
* 1. State
frame create state
frame change state

use "$clean/qcew/state_sample.dta", clear
rename annual_avg_emplvl55 annual_avg_emplvl75


* 2. MSCZ

frame create msczes
frame change msczes

use "$clean/qcew/mscz_sample.dta", clear


* 3. BCP

frame create bcpes
frame change bcpes

use "$clean/qcew/bcp_sample.dta", clear

forvalues i = 1/4 {
	frame create bcpes_ss`i'
	frame change bcpes_ss`i'
	use "$clean/qcew/bcp_subsample`i'.dta", clear
}


************************************************
* Constructing events, post-periods, clean controls
************************************************

* for event study, we use emp/pop as dependent variable instead of using emp 
* as dependent variable and adding pop as control

foreach f in state msczes bcpes bcpes_ss1 bcpes_ss2 bcpes_ss3 bcpes_ss4 {
	frame `f': gen lepop75 = ln(annual_avg_emplvl75/pop)
}


local f = 1 
foreach frame in state msczes bcpes bcpes_ss1 bcpes_ss2 bcpes_ss3 bcpes_ss4 {
	if `f' == 1 {
		local unit = "statefips"
	}
	
	if `f' == 2 {
		local unit = "pair_id_czstate"
	}
	
	if `f' >= 3 {
		local unit = "pair_id_county"
	}
	
	frame change `frame'
	
	* get 1980s MW data
	preserve
		use "$raw/other/mw_state_annual_vz.dta", clear
		gen mw = max(max_mw, max_fed_mw)
		keep statefips year mw
		keep if inrange(year,1987,1989)
		
		tempfile mw
		save `mw'
	restore
	
	forvalues i = 1987/1989 {
		insobs 1
		replace year = `i' if _n == _N
	}

	fillin `unit' year
	drop if mi(`unit')
	if `f' >= 2 {
		bys `unit' (year): replace statefips = statefips[_N] if mi(statefips)
		assert ~mi(statefips)
	}
	

	merge m:1 statefips year using `mw', update
	drop if _merge == 2  //Alaska, Hawaii, DC
	drop _merge
	assert ~mi(mw)
	replace lmw = ln(mw) if mi(lmw)
	assert ~mi(lmw)  
	xtset `unit' year
	
	* create pre-and post-means and difference variables
	foreach var in lemp75 learn75 lepop75 lmw lpop lemp_other learn_other {
		forvalues i = 1/5 {
			gen `var'_f`i' = F`i'.`var'
		}
	
	* the years below are divided into different groups as per their maximum post-period length
			
			
			gen `var'_pre = L.`var'
			egen `var'_post = rowmean(`var' `var'_f1 `var'_f2 `var'_f3 `var'_f4 `var'_f5) ///
			if inrange(year,1998,2001) | inrange(year,2010,2014)
			egen `var'_postb = rowmean(`var' `var'_f1 `var'_f2 `var'_f3 `var'_f4) if ///
			inlist(year,2002,2015)
			egen `var'_postc = rowmean(`var' `var'_f1 `var'_f2 `var'_f3) if ///
			inlist(year,1992,2003,2016)
			egen `var'_postd = rowmean(`var' `var'_f1 `var'_f2) if ///
			inlist(year,1993,2004,2017)
			egen `var'_poste = rowmean(`var' `var'_f1) if inlist(year,1994,2005,2018)
			gen `var'_postf = `var' if inlist(year,1995,2006,2019)
			
			replace `var'_post = `var'_postb if inlist(year,2002,2015)
			replace `var'_post = `var'_postc if inlist(year,1992,2003,2016)
			replace `var'_post = `var'_postd if inlist(year,1993,2004,2017)
			replace `var'_post = `var'_poste if inlist(year,1994,2005,2018)
			replace `var'_post = `var'_postf if inlist(year,1995,2006,2019)

			drop `var'_postb `var'_postc `var'_postd `var'_poste `var'_postf
			
			gen `var'_dif = `var'_post - `var'_pre
			
			
		}
		
		gen max_lmw_dif = .
		replace max_lmw_dif = F5.lmw - L.lmw if inrange(year,1998,2001) | inrange(year,2010,2014)
		replace max_lmw_dif = F4.lmw - L.lmw if inlist(year,2002,2015)
		replace max_lmw_dif = F3.lmw - L.lmw if inlist(year,1992,2003,2016)
		replace max_lmw_dif = F2.lmw - L.lmw if inlist(year,1993,2004,2017)
		replace max_lmw_dif = F.lmw - L.lmw if inlist(year,1994,2005,2018)
		replace max_lmw_dif = lmw - L.lmw if inlist(year,1995,2006,2019)

		
		gen max_mw_dif = .
		replace max_mw_dif = F5.mw - L.mw if inrange(year,1998,2001) | inrange(year,2010,2014)
		replace max_mw_dif = F4.mw - L.mw if inlist(year,2002,2015)
		replace max_mw_dif = F3.mw - L.mw if inlist(year,1992,2003,2016)
		replace max_mw_dif = F2.mw - L.mw if inlist(year,1993,2004,2017)
		replace max_mw_dif = F.mw - L.mw if inlist(year,1994,2005,2018)
		replace max_mw_dif = mw - L.mw if inlist(year,1995,2006,2019)

	
			
		* create events

		gen initial_event = mw >= 1.05*L.mw & mw >= L.mw + 0.25 & mw > fed_mw & ~inlist(year,1988,1989)

		gen admissible_event = initial_event == 1 & ~inlist(year,1990,1991,1996,1997,2007,2008,2009)


		gen event_combined = admissible_event == 1 & L.admissible_event == 0 & ///
		L2.admissible_event == 0 & L3.admissible_event == 0

		preserve
			import excel using "$raw/other/indexed_mw.xlsx", firstrow clear
			tempfile index
			save `index'
		restore

		
		merge m:1 statefips using `index', keep(1 3) nogen
		gen indexed_mw = year >= index_start
		
		sort `unit' year, stable
		
		* "rolling back" - see Appendix for details
		gen check1 = event_combined == 1 & L.mw > L2.mw & ///
		~inlist(L.year,1990,1991,1996,1997,2007,2008,2009) & L.indexed_mw == 0

		replace event_combined = 0 if check1 == 1
		replace event_combined = 1 if F.check1 == 1
		replace check1 = 1 if F.check1 == 1

		gen check2 = event_combined == 1 & check1 == 1 & L.mw > L2.mw & ///
		~inlist(L.year,1990,1991,1996,1997,2007,2008,2009) & L.indexed_mw == 0

		replace event_combined = 0 if check2 == 1
		replace event_combined = 1 if F.check2 == 1
		replace check2 = 1 if F.check2 == 1

		gen check3 = event_combined == 1 & check2 == 1 & L.mw > L2.mw & ///
		~inlist(L.year,1990,1991,1996,1997,2007,2008,2009) & L.indexed_mw == 0

		* no states left, so these are our final "provisional" events

		* one change for vermont, as even though increase is in an "indexed" period, and small, we know it was a state legislated increase

		replace event_combined = 1 if year == 2015 & statename == "Vermont"
		replace event_combined = 0 if year == 2018 & statename == "Vermont"

		/*we manually remove some events that are overlapping with post periods of other
		events. There are 4 such instances - Delaware 2014 and 2019; 
		New Jersey 2014 and 2019; Oregon 1998 and 2003; and Rhode Island 1999 and 2004. 
		We have to decide whether to keep the latter year only in the former event, 
		or let the latter year be a standalone event by itself. We choose the first option
		(which amounts to removing the latter event) if the MW increase in the post-period
		of the latter event is smaller than the MW increase in the post-period of the former
		event. If this is not the case, we keep both events and reduce the post-period of 
		the former event by one year (so that the latter event is no longer in the post-period
		of the former.) In practice, we choose the first option for all four cases 
		- i.e their latter events get dropped and get evaluated 
		as part of the earlier event. */

		replace event_combined = 0 if (statename == "Delaware" & year == 2019) | ///
		(statename == "New Jersey" & year == 2019) | (statename == "Oregon" & year == 2003) ///
		| (statename == "Rhode Island" & year == 2004)
		
		* create a new variable that only has events without any federal increases in the three-year 
		* pre-period as well
		
		gen event_combined_long = event_combined == 1 & ~inrange(year,1992,1994) ///
		& ~inrange(year,1998,2000) & ~inrange(year,2010,2012)

		* create clean controls
			
		gen mw_increase = mw > L.mw & mw > fed_mw

		gen clean_control = 0

		replace clean_control = 1 if inlist(year,1995,2006,2019) & ///
		L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
		& mw_increase == 0

		replace clean_control = 1 if inlist(year,1994,2005,2018) & ///
		L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
		& mw_increase == 0 & F.mw_increase == 0

		replace clean_control = 1 if inlist(year,1993,2004,2017) & ///
		L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
		& mw_increase == 0 & F.mw_increase == 0 & F2.mw_increase == 0

		replace clean_control = 1 if inlist(year,1992,2003,2016) & ///
		L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
		& mw_increase == 0 & F.mw_increase == 0 & F2.mw_increase == 0 & ///
		F3.mw_increase == 0

		replace clean_control = 1 if inlist(year,2002,2015) & ///
		L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
		& mw_increase == 0 & F.mw_increase == 0 & F2.mw_increase == 0 & ///
		F3.mw_increase == 0 & F4.mw_increase == 0 

		replace clean_control = 1 if (inrange(year,1998,2001) ///
		| inrange(year,2010,2014)) & L.mw_increase == 0 & L2.mw_increase == 0 & ///
		L3.mw_increase == 0 & mw_increase == 0 & F.mw_increase == 0 & ///
		F2.mw_increase == 0 & F3.mw_increase == 0 & F4.mw_increase == 0 & ///
		F5.mw_increase == 0
		
		frame copy `frame' `frame'_00
		frame `frame'_00: keep if year >= 2000
	
local ++f
}

frame msczes: save "$intermediate/qcew_msczes.dta", replace
frame bcpes: save "$intermediate/qcew_bcpes.dta", replace


************************************************
* Creating frames for event study figures
************************************************

* first for standard event study figure

frame copy msczes msczesfig
frame copy bcpes bcpfig
foreach frame in msczesfig bcpfig {
	frame `frame' {
		foreach var in lepop75 learn75 lmw {
			forvalues i = 1/3 {
				gen `var'pre`i' = L`i'.`var'
			}
			
			forvalues i = 1/5 {
				gen `var'post`i' = F`i'.`var'
			}
			
			local j = 1
			forvalues i = 3(-1)1 {
				gen `var'_dif`j' = `var'pre`i' - `var'pre1
				local ++j
			}
			
			gen `var'_dif4 = `var' - `var'pre1
			
			local j = 5
			forvalues i = 1/5 {
				gen `var'_dif`j' = `var'post`i' - `var'pre1
				local ++j
			}
			
			forvalues i = 1/9 {
				replace `var'_dif`i' = . if inlist(year,1990,1991,1996,1997,2007,2008,2009)
			}
			
			replace `var'_dif9 = . if inrange(year,1992,1995) | inrange(year,2002,2006) | inrange(year,2015,2019)
			replace `var'_dif8 = . if inrange(year,1992,1995) | inrange(year,2003,2006) | inrange(year,2016,2019)
			replace `var'_dif7 = . if inrange(year,1993,1995) | inrange(year,2004,2006) | inrange(year,2017,2019)
			replace `var'_dif6 = . if inrange(year,1994,1995) | inrange(year,2005,2006) | inrange(year,2018,2019)
			replace `var'_dif5 = . if inlist(year,1995,2006,2019)
			}
	}
}


* next for longer event study figures (to see pre-trends)

frame copy msczes msczesfig2
frame copy bcpes bcpfig2

forvalues i = 1/4 {
	frame copy bcpes_ss`i' bcp_ss`i'fig2
}

local f = 1
foreach frame in msczesfig2 bcpfig2 bcp_ss1fig2 bcp_ss2fig2 bcp_ss3fig2 bcp_ss4fig2 {
	
	
	if `f' == 1 {
		local unit = "pair_id_czstate"
	}
	
	if `f' >= 2 {
		local unit = "pair_id_county"
	}
	
	frame `frame' {
		foreach var in lepop75 lemp75 learn75 lmw lemp_other lpop {
			forvalues i = 1/3 {
				gen `var'pre`i' = L`i'.`var'
			}
			
			forvalues i = 1/5 {
				gen `var'post`i' = F`i'.`var'
			}
			
			local j = 1
			forvalues i = 3(-1)1 {
				gen _`var'_dif`j' = `var'pre`i' - `var'pre1
				local ++j
			}
			
			gen _`var'_dif4 = `var' - `var'pre1
			
			local j = 5
			forvalues i = 1/5 {
				gen _`var'_dif`j' = `var'post`i' - `var'pre1
				local ++j
			}
			
			forvalues i = 1/9 {
				replace _`var'_dif`i' = . if inlist(year,1990,1991,1996,1997,2007,2008,2009)
			}
			
			replace _`var'_dif9 = . if inrange(year,1992,1995) | inrange(year,2002,2006) | inrange(year,2015,2019)
			replace _`var'_dif8 = . if inrange(year,1992,1995) | inrange(year,2003,2006) | inrange(year,2016,2019)
			replace _`var'_dif7 = . if inrange(year,1993,1995) | inrange(year,2004,2006) | inrange(year,2017,2019)
			replace _`var'_dif6 = . if inrange(year,1994,1995) | inrange(year,2005,2006) | inrange(year,2018,2019)
			replace _`var'_dif5 = . if inlist(year,1995,2006,2019)
			
			forval j = 1990/1998 {
				
				gen _`var'_longpre`j' = `var' if year == `j'
				bys `unit' (year): egen `var'_longpre`j' = mean(_`var'_longpre)
				replace `var'_longpre`j' = . if inlist(year,1990,1991,1996,1997,2007,2008,2009)
			
				drop _`var'_longpre*
			}
			
			
			local j=1
			forvalues i=1990/1998 {
				g `var'_dif`j' = `var'_longpre`i' - `var'pre1
				g `var'_dif`j'_2 = `var'_longpre`i' - `var'pre3
				local ++j
			}
			
			
			forvalues i=1/9 {
				g `var'_dif`j' = _`var'_dif`i'
				local ++j
			}
			
			drop _`var'_dif*
			}
		keep if year >= 2000
	}
	
	local ++f
}



* now for figure showing MW events

frame copy state events_fig
frame change events_fig
gen mw_increase_fig = 0

replace mw_increase_fig = 1 if mw>L.mw & mw == fed_mw
replace mw_increase_fig = 2 if (mw>L.mw) & ((mw<1.05*L.mw) | (mw<L.mw + 0.25)) & mw>fed_mw
replace mw_increase_fig = 3 if mw>=1.05*L.mw & mw>=L.mw + 0.25 & mw>fed_mw
replace mw_increase_fig = 4 if event_combined == 1
replace mw_increase_fig = 5 if inlist(mw_increase_fig,2,3) & ///
~inlist(year,1981,1990,1991,1996,1997,2007,2008,2009) & (L.event_combined == 1 | ///
L2.event_combined == 1 | L3.event_combined == 1 | L4.event_combined == 1 | L5.event_combined == 1)
gen mw_increase_state = mw_increase_fig!=0 & mw_increase_fig!=1
tab mw_increase_state 

encode state_abb, gen(stateindex)




************************************************
* Frames for robustness - changing pre-period
************************************************

foreach frame in msczes bcpes {
	frame copy `frame' `frame'_pre2
	frame change `frame'_pre2
	
	replace clean_control = 0
	
	replace clean_control = 1 if inlist(year,1995,2006,2019) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & mw_increase == 0

	replace clean_control = 1 if inlist(year,1994,2005,2018) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & mw_increase == 0 & ///
	F.mw_increase == 0

	replace clean_control = 1 if inlist(year,1993,2004,2017) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & mw_increase == 0 & ///
	F.mw_increase == 0 & F2.mw_increase == 0

	replace clean_control = 1 if inlist(year,1992,2003,2016) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & mw_increase == 0 & ///
	F.mw_increase == 0 & F2.mw_increase == 0 & F3.mw_increase == 0

	replace clean_control = 1 if inlist(year,2002,2015) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & mw_increase == 0 & ///
	F.mw_increase == 0 & F2.mw_increase == 0 & F3.mw_increase == 0 & ///
	F4.mw_increase == 0 

	replace clean_control = 1 if (inrange(year,1998,2001) ///
	| inrange(year,2010,2014)) & L.mw_increase == 0 & L2.mw_increase == 0 & ///
	mw_increase == 0 & F.mw_increase == 0 & F2.mw_increase == 0 & ///
	F3.mw_increase == 0 & F4.mw_increase == 0 & F5.mw_increase == 0
	
	frame copy `frame' `frame'_pre4
	frame change `frame'_pre4
	
	replace clean_control = 0
	
	replace clean_control = 1 if inlist(year,1995,2006,2019) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
	& L4.mw_increase == 0 & mw_increase == 0

	replace clean_control = 1 if inlist(year,1994,2005,2018) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
	& L4.mw_increase == 0 & mw_increase == 0 & F.mw_increase == 0

	replace clean_control = 1 if inlist(year,1993,2004,2017) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
	& L4.mw_increase == 0 & mw_increase == 0 & F.mw_increase == 0 & ///
	F2.mw_increase == 0

	replace clean_control = 1 if inlist(year,1992,2003,2016) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
	& L4.mw_increase == 0 & mw_increase == 0 & F.mw_increase == 0 & ////
	F2.mw_increase == 0 & F3.mw_increase == 0

	replace clean_control = 1 if inlist(year,2002,2015) & ///
	L.mw_increase == 0 & L2.mw_increase == 0 & L3.mw_increase == 0 ///
	& L4.mw_increase == 0 & mw_increase == 0 & F.mw_increase == 0 & ///
	F2.mw_increase == 0 & F3.mw_increase == 0 & F4.mw_increase == 0  

	replace clean_control = 1 if (inrange(year,1998,2001) ///
	| inrange(year,2010,2014)) & L.mw_increase == 0 & L2.mw_increase == 0 & ///
	L3.mw_increase == 0 & L4.mw_increase == 0 & mw_increase == 0 & ///
	F.mw_increase == 0 & F2.mw_increase == 0 & F3.mw_increase == 0 & ///
	F4.mw_increase == 0 & F5.mw_increase == 0
	
	foreach i in 2 4 {
		frame copy `frame'_pre`i' `frame'_pre`i'_00
		frame `frame'_pre`i'_00: keep if year>=2000
	}
}


************************************************
* Frames for robustness - including federal events
************************************************

frame copy state state_post_periods
frame change state_post_periods

gen post_period = .
replace post_period = 6 if initial_event == 0 & F.initial_event == 0 & ///
F2.initial_event == 0 & F3.initial_event == 0 & F4.initial_event == 0 & ///
F5.initial_event == 0

replace post_period = 5 if initial_event == 0 & F.initial_event == 0 & ///
F2.initial_event == 0 & F3.initial_event == 0 & F4.initial_event == 0 & ///
F5.initial_event == 1

replace post_period = 4 if initial_event == 0 & F.initial_event == 0 & ///
F2.initial_event == 0 & F3.initial_event == 0 & F4.initial_event == 1

replace post_period = 3 if initial_event == 0 & F.initial_event == 0 & ///
F2.initial_event == 0 & F3.initial_event == 1

replace post_period = 2 if initial_event == 0 & F.initial_event == 0 & ///
F2.initial_event == 1

replace post_period = 1 if initial_event == 0 & F.initial_event == 1

replace post_period = 0 if initial_event == 1

keep if inlist(year,1996,2008)
merge m:1 statefips year using "$raw/other/mw_state_annual_vz.dta", ///
keepusing(min_mw) assert(2 3) keep(3) nogen

gen bounded_federal = (year == 2008 & min_mw < 6.55) | (year == 1996 & min_mw < 4.75)
replace post_period = 6 if bounded_federal == 1

tempfile post_periods
save `post_periods'


local f = 1
foreach frame in msczes bcpes {
	
	if `f' == 1 {
		local unit = "pair_id_czstate"
	}
	
	if `f' == 2 {
		local unit = "pair_id_county"
	}
	
	frame copy `frame' `frame'_federal
	frame change `frame'_federal
	merge m:1 statefips year using `post_periods', ///
	keepusing(bounded_federal post_period) keep(1 3) nogen
	replace event_combined = 1 if bounded_federal == 1
	replace clean_control = 1 if bounded_federal == 0 & post_period>0
	
	bys pair_id_num year: egen min_post_period = min(post_period) if inlist(year,1996,2008)
	
	sort `unit' year, stable
	
	foreach var in learn75 lemp75 lepop75 lmw {
		replace `var'_post = (`var' + F.`var' + F2.`var' + F3.`var' + F4.`var' + F5.`var')/6 if min_post_period == 6
		replace `var'_post = (`var' + F.`var' + F2.`var' + F3.`var' + F4.`var')/5 if min_post_period == 5
		replace `var'_post = (`var' + F.`var' + F2.`var' + F3.`var')/4 if min_post_period == 4
		replace `var'_post = (`var' + F.`var' + F2.`var')/3 if min_post_period == 3
		replace `var'_post = (`var' + F.`var')/2 if min_post_period == 2
		replace `var'_post = `var' if min_post_period == 1
		replace `var'_post = . if min_post_period == 0
		
		replace `var'_dif = `var'_post - `var'_pre if ~mi(post_period)
	}
	
	replace max_lmw_dif = F5.lmw - L.lmw if min_post_period == 6
	replace max_lmw_dif = F4.lmw - L.lmw if min_post_period == 5
	replace max_lmw_dif = F3.lmw - L.lmw if min_post_period == 4
	replace max_lmw_dif = F2.lmw - L.lmw if min_post_period == 3
	replace max_lmw_dif = F.lmw - L.lmw if min_post_period == 2
	replace max_lmw_dif = lmw - L.lmw if min_post_period == 1
	
	local ++f
}

************************************************
* Frames for robustness - cohorts by length of 
* post-period
************************************************
frame copy msczesfig msczes_cohorts
frame copy bcpfig bcp_cohorts

foreach frame in msczes_cohorts bcp_cohorts {
	frame change `frame'
	gen post_period_cohort = .
	
	replace post_period_cohort = 1 if inlist(year,1995,2006,2019)
	replace post_period_cohort = 2 if inlist(year,1994,2005,2018)
	replace post_period_cohort = 3 if inlist(year,1993,2004,2017)
	replace post_period_cohort = 4 if inlist(year,1992,2003,2016)
	replace post_period_cohort = 5 if inlist(year,2002,2015)
	replace post_period_cohort = 6 if inrange(year,1998,2001) | inrange(year,2010,2014)
	
	foreach var in lepop75 learn75 {
		gen `var'_dif4_cum = `var' - `var'pre1
		gen `var'_dif5_cum = (`var' + `var'post1)/2 - `var'pre1
		gen `var'_dif6_cum = (`var' + `var'post1 + `var'post2)/3 - `var'pre1
		gen `var'_dif7_cum = (`var' + `var'post1 + `var'post2 + `var'post3)/4 - `var'pre1
		gen `var'_dif8_cum = (`var' + `var'post1 + `var'post2 + `var'post3 + `var'post4)/5 - `var'pre1
		gen `var'_dif9_cum = (`var' + `var'post1 + `var'post2 + `var'post3 + `var'post4 + `var'post5)/6 - `var'pre1
	}
}



**************************************************************************
* Part 2: Run regressions, and output figures and tables
**************************************************************************

************************************************
* Event study regressions
************************************************

local f = 1 
foreach frame in msczes msczes_00 bcpes bcpes_00 {
	frame `frame' {
		
		
		local a = "pair_id_num##year"
		bys pair_id_num year: egen event_total = total(event_combined)
		bys pair_id_num year: egen control_total = total(clean_control)
		
		eststo `frame'_earn_uw: reghdfe learn75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lepop75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		eststo `frame'_mwe_uw: ivreghdfe lepop75_dif (max_lmw_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lepop75_dif (learn75_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)
		eststo `frame'_emp_w: reghdfe lepop75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)
		eststo `frame'_mwe_w: ivreghdfe lepop75_dif (max_lmw_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lepop75_dif (learn75_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)	
		
		
		preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
	
		
		if inrange(`f',3,4) {
			estadd local fe " "
			estadd local czp_fe "Y"
			estadd local bcp_fe " "
			estadd local gap " "
			estadd local samples " "
			estadd local state_sample " "
			estadd local mscz_sample "Y"
			estadd local bcp_sample " "
		}
		
		if `f'>=5 {
			estadd local fe " "
			estadd local czp_fe " "
			estadd local bcp_fe "Y"
			estadd local gap " "
			estadd local samples " "
			estadd local state_sample " "
			estadd local mscz_sample " "
			estadd local bcp_sample "Y"
		}
		
		
	}
	local ++f
}

* output es table

esttab msczes_earn_uw bcpes_earn_uw msczes_00_earn_uw bcpes_00_earn_uw ///
using "$tables/Table 3.tex", replace booktabs b(3) se(3) nomtitles keep(event_combined) ///
varlabels(event_combined "Log wages") nonote noobs star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
mgroups("1990-2019" "2000-2019", pattern(1 0 1 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
title(Effects of increased MW - event study estimates with QCEW data \label{tab:es1}) ///
postfoot( ) ///
posthead(\midrule \\ ///
\multicolumn{5}{l}{\textbf{A. Unweighted}} \\ & & & \\)

esttab msczes_emp_uw bcpes_emp_uw msczes_00_emp_uw bcpes_00_emp_uw ///
using "$tables/Table 3.tex", append booktabs b(3) se(3) nomtitles keep(event_combined) ///
varlabels(event_combined "Log employment rate") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_mwe_uw bcpes_mwe_uw msczes_00_mwe_uw bcpes_00_mwe_uw ///
using "$tables/Table 3.tex", append booktabs b(3) se(3) nomtitles keep(max_lmw_dif) ///
varlabels(max_lmw_dif "MWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_owe_uw bcpes_owe_uw msczes_00_owe_uw bcpes_00_owe_uw ///
using "$tables/Table 3.tex", append booktabs b(3) se(3) nomtitles keep(learn75_dif) ///
varlabels(learn75_dif "OWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_earn_w bcpes_earn_w msczes_00_earn_w bcpes_00_earn_w ///
using "$tables/Table 3.tex", append booktabs b(3) se(3) nomtitles keep(event_combined) ///
varlabels(event_combined "Log wages") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
prehead(\multicolumn{5}{l}{\textbf{B. Weighted by population}} ///
\\ & & & \\) postfoot( ) posthead( )

esttab msczes_emp_w bcpes_emp_w msczes_00_emp_w bcpes_00_emp_w ///
using "$tables/Table 3.tex", append booktabs b(3) se(3) nomtitles keep(event_combined) ///
varlabels(event_combined "Log employment rate") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_mwe_w bcpes_mwe_w msczes_00_mwe_w bcpes_00_mwe_w ///
using "$tables/Table 3.tex", append booktabs b(3) se(3) nomtitles keep(max_lmw_dif) ///
varlabels(max_lmw_dif "MWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_owe_w bcpes_owe_w msczes_00_owe_w bcpes_00_owe_w ///
using "$tables/Table 3.tex", append booktabs b(3) se(3) nomtitles keep(learn75_dif) ///
varlabels(learn75_dif "OWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
stats(N gap num_events gap fe czp_fe bcp_fe gap samples mscz_sample bcp_sample, ///
labels("\textbf{N}" " " "\textbf{Events evaluated}" " " "\textbf{Fixed effects}" "MSCZ pair-year" "BC pair-year" ///
" " "\textbf{Sample}" "MSCZ pairs" "Border county pairs") ///
fmt(%9.0fc)) /// 
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
\textit{Notes:} Estimated using specification described in equation \ref{eq:ES} ///
using Quarterly Census of Employment and Wages data. Columns (1) and (2) use the ///
years 1990-2019, and (3) and (4) use 2000-2019. Columns (1) and (3) use multi-state ///
commuting-zone-by-state pairs sample and include pair-year fixed effects. ///
Columns (2) and (4) similarly use the sample of border county pairs and also ///
include pair-year fixed effects. Outcomes include log weekly earnings, log ///
employment rate, minimum wage elasticity (MWE) and own wage elasticity (OWE). ///
MWE is the IV estimate from regressing log employment rate on the log minimum wage ///
instrumented by the event dummy. OWE is the IV estimate from ///
regressing log employment rate on log earnings instrumented by the event dummy. ///
Estimates in Panel A are unweighted, while estimates in Panel B are weighted using the working-age population. ///
The estimation sample for all years includes all units that are either newly treated or are clean controls for ///
that year. However, the number of events evaluated is calculated only from pair-years that exhibit ///
treatment variation - i.e one side of the pair has an event start, while the other side is a clean control ///
as defined in the text. ///
Standard errors, reported in parentheses, are clustered at the ///
state level. Stars indicate statistical significance as follows: \sym{*} \(p<0.10\), ///
\sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
)

**************************************************
* Pre-trend analysis
**************************************************

frame create cbp_msczes
frame change cbp_msczes
use "$out/intermediate_results/cbp_msczes.dta", clear

local f = 1
foreach frame in cbp_msczes msczesfig2 bcpfig2 bcp_ss1fig2 bcp_ss2fig2 bcp_ss3fig2 bcp_ss4fig2 {
	frame change `frame'
	
	bys pair_id_num year: egen event_total = total(event_combined)
	bys pair_id_num year: egen control_total = total(clean_control)
	
	foreach i in 1 4 8 {
		eststo `frame'_`i': reghdfe lepop75_dif`i' event_combined if ///
		(event_combined == 1 | clean_control == 1), a(pair_id_num##year) ///
		cluster(statefips)
		if `f' == 1 {
			estadd local cbp "Y"
		}
		
		else {
			estadd local cbp " "
		}
		
		estadd local lemp " "
		estadd local controls " "
		estadd local weight " "
		if `i' == 1 {
			estadd local year90 "Y"
			estadd local year97 " "
		}
		
		if `i' == 4 {
			estadd local year90 " "
			estadd local year97 " "
		}
		
		if `i' == 8 {
			estadd local year90 " "
			estadd local year97 "Y"
		}
		
		preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
		
		eststo `frame'_`i'_w: reghdfe lepop75_dif`i' event_combined if ///
		(event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) ///
		cluster(statefips)
		
		if `f' == 1 {
			estadd local cbp "Y"
		}
		
		else {
			estadd local cbp " "
		}
		estadd local lemp " "
		estadd local controls " "
		estadd local weight "Y"
		if `i' == 1 {
			estadd local year90 "Y"
			estadd local year97 " "
		}
		
		if `i' == 4 {
			estadd local year90 " "
			estadd local year97 " "
		}
		
		if `i' == 8 {
			estadd local year90 " "
			estadd local year97 "Y"
		}
		
		preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
		
		eststo `frame'_`i'_2: reghdfe lepop75_dif`i'_2 event_combined if ///
		(event_combined == 1 | clean_control == 1), a(pair_id_num##year) ///
		cluster(statefips)
		
		if `f' == 1 {
			estadd local cbp "Y"
		}
		
		else {
			estadd local cbp " "
		}
		estadd local lemp " "
		estadd local controls " "
		estadd local weight " "
		if `i' == 1 {
			estadd local year90 "Y"
			estadd local year97 " "
		}
		
		if `i' == 4 {
			estadd local year90 " "
			estadd local year97 " "
		}
		
		if `i' == 8 {
			estadd local year90 " "
			estadd local year97 "Y"
		}
		
		preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
		
		eststo `frame'_`i'_w_2: reghdfe lepop75_dif`i'_2 event_combined if ///
		(event_combined == 1 | clean_control == 1), a(pair_id_num##year) ///
		cluster(statefips)
		
		if `f' == 1 {
			estadd local cbp "Y"
		}
		
		else {
			estadd local cbp " "
		}
		estadd local lemp " "
		estadd local controls " "
		estadd local weight "Y"
		if `i' == 1 {
			estadd local year90 "Y"
			estadd local year97 " "
		}
		
		if `i' == 4 {
			estadd local year90 " "
			estadd local year97 " "
		}
		
		if `i' == 8 {
			estadd local year90 " "
			estadd local year97 "Y"
		}
		
		preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
	}
	
local ++f
}

local f=1
foreach frame in cbp_msczes msczesfig2 bcpfig2 bcp_ss1fig2 bcp_ss2fig2 bcp_ss3fig2 bcp_ss4fig2 {
	frame change `frame'
	foreach i in 1 4 8 {
		eststo jnr_`frame'_`i': reghdfe lemp75_dif`i' event_combined ///
		lemp_other_dif`i' lpop_dif`i' if ///
		(event_combined == 1 | clean_control == 1), a(pair_id_num##year) ///
		cluster(statefips)
		
		if `f' == 1 {
			estadd local cbp "Y"
		}
		
		else {
			estadd local cbp " "
		}
		estadd local lemp "Y"
		estadd local controls "Y"
		estadd local weight " "
		if `i' == 1 {
			estadd local year90 "Y"
			estadd local year97 " "
		}
		
		if `i' == 4 {
			estadd local year90 " "
			estadd local year97 " "
		}
		
		if `i' == 8 {
			estadd local year90 " "
			estadd local year97 "Y"
		}
		
		preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
		
		eststo jnr_`frame'_`i'_2: reghdfe lepop75_dif`i'_2 event_combined ///
		lemp_other_dif`i'_2 lpop_dif`i'_2 if ///
		(event_combined == 1 | clean_control == 1), a(pair_id_num##year) ///
		cluster(statefips)
		
		if `f' == 1 {
			estadd local cbp "Y"
		}
		
		else {
			estadd local cbp " "
		}
		estadd local lemp "Y"
		estadd local controls "Y"
		estadd local weight " "
		if `i' == 1 {
			estadd local year90 "Y"
			estadd local year97 " "
		}
		
		if `i' == 4 {
			estadd local year90 " "
			estadd local year97 " "
		}
		
		if `i' == 8 {
			estadd local year90 " "
			estadd local year97 "Y"
		}
		
		preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
	}
local ++f
}


esttab msczesfig2_4 cbp_msczes_4 jnr_msczesfig2_4 jnr_cbp_msczes_4 msczesfig2_4_w ///
msczesfig2_1 msczesfig2_8 bcpfig2_4 bcp_ss1fig2_4 bcp_ss3fig2_4 using "$tables/Table D3.tex", ///
replace booktabs b(3) se(3) mtitles(" " " " " " " " " " " " " " ///
"\shortstack{All\\BCP}" "\shortstack{Non-MSCZ\\BCP (JNR\\sub-sample 1)}" "\shortstack{MSCZ county\\pairs (JNR\\sub-sample 3)}") ///
keep(event_combined) varlabels(event_combined "Trend until t[-1]") nonote noobs ///
star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
mgroups("MSCZ pairs" "County pairs", pattern(1 0 0 0 0 0 0 1 0 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
title(Pre-trends check for post-2000 events \label{tab:pre_trends}) postfoot( ) ///
substitute("\_" "_")


esttab msczesfig2_4_2 cbp_msczes_4_2 jnr_msczesfig2_4_2 jnr_cbp_msczes_4_2 ///
msczesfig2_4_w_2 msczesfig2_1_2 msczesfig2_8_2 bcpfig2_4_2 bcp_ss1fig2_4_2 bcp_ss3fig2_4_2 ///
using "$tables/Table D3.tex", append booktabs b(3) se(3) nomtitles keep(event_combined) ///
varlabels(event_combined "Trend until t[-3]") nonote nonum star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
stats(N cbp lemp controls weight year90 year97 num_events, ///
labels("N" "CBP dataset" "\shortstack{Outcome is\\log emp}" "\shortstack{Pop and non-rest\\emp controls}" ///
"\shortstack{Weighted by\\population}" "Start year 1990" "Start year 1997" "Events evaluated") ///
fmt(%9.0fc)) ///
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
This table reports coefficients from the specification described in Equation ///
\ref{eq:ES_dynamic_pre_trends}, with the outcome being log of employment rate in ///
all columns apart from Columns 3 and 4. The top row is the exact specification ///
as the equation, while the bottom row takes the trend until t[-3] in event-time ///
instead of t[-1]. Unless indicated otherwise ///
(only in Columns 6 and 7), the long difference is taken ///
from 1993. The dataset is QCEW in all columns apart from Column 2 and 4. All estimates, with ///
the exception of Column 5 are unweighted. Columns 1 - 7 use data from MSCZ pairs, while ///
Columns 8 - 10 use pairs of counties. Column 8 uses all border county pairs, while Columns ///
9 and 10 correspond to sub-samples 1 and 3 as identified by JNR. ///
Standard errors, reported in parentheses, are clustered at the ///
state level. Stars indicate statistical significance as follows: \sym{*} \(p<0.10\), ///
\sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
) ///
substitute("\_" "_")



***************************************************
* Event study figures
***************************************************

* Standard figures

* Regressions

local f = 1
foreach frame in msczesfig bcpfig {
	frame change `frame'
	
	local a = "pair_id_num##year"
	foreach var in lmw lepop75 learn75 {
		forvalues i = 1/9 {
			reghdfe `var'_dif`i' event_combined if (event_combined == 1 | clean_control == 1) ///
			, a(`a') cluster(statefips)
			
			if `i' == 1 {
				matrix `frame'_`var' = (r(table)[1,1], r(table)[5,1],r(table)[6,1])
			}
			
			else {
				matrix `frame'_`var'`i' = (r(table)[1,1], r(table)[5,1],r(table)[6,1])
				matrix `frame'_`var' = (`frame'_`var' \ `frame'_`var'`i')
			}
		}
		
		frame create `frame'_`var'
		frame change `frame'_`var'
		svmat `frame'_`var',names(est)
		
		foreach v in est2 est3 {
			replace `v' = 0 if mi(`v')
		}
		
		gen eventtime = _n - 4
		frame change `frame'
	}
local ++f
}



* figures
frame msczesfig_lmw: twoway (line est1 eventtime, lcolor(blue*0.5) lpattern(solid)) ///
(rcap est2 est3 eventtime, lcolor(blue*0.5) lpattern(dash)), ///
xtitle(Years around MW increase event, size(small)) xlabel(-3(1)5, labsize(vsmall)) ///
ytitle("Change in" "log minimum wage", size(small)) legend(off) ///
yline(0) ylabel(-0.05(0.05)0.35, labsize(vsmall)) title(A. Log Minimum Wage (MSCZ pairs sample), size(small)) ///
name(es_mw_mscz, replace)

frame bcpfig_lmw: twoway (line est1 eventtime, lcolor(blue*0.5) lpattern(solid)) ///
(rcap est2 est3 eventtime, lcolor(blue*0.5) lpattern(dash)), ///
xtitle(Years around MW increase event, size(small)) xlabel(-3(1)5, labsize(vsmall)) ///
ytitle("Change in" "log minimum wage", size(small)) legend(off) ///
yline(0) ylabel(-0.05(0.05)0.35, labsize(vsmall)) title(B. Log Minimum Wage (BC pairs sample), size(small)) ///
name(es_mw_bcp, replace)

frame msczesfig_learn75: twoway (line est1 eventtime, lcolor(blue*0.5) lpattern(solid)) ///
(rcap est2 est3 eventtime, lcolor(blue*0.5) lpattern(dash)), ///
xtitle(Years around MW increase event, size(small)) xlabel(-3(1)5, labsize(vsmall)) ///
ytitle("Change in" "log average weekly earnings", size(small)) legend(off) ///
yline(0) ylabel(-0.06(0.03)0.12, labsize(vsmall)) title(C. Log Earnings (MSCZ pairs sample), size(small)) ///
name(es_earn_mscz, replace)

frame msczesfig_lepop75: twoway (line est1 eventtime, lcolor(blue*0.5) lpattern(solid)) ///
(rcap est2 est3 eventtime, lcolor(blue*0.5) lpattern(dash)), ///
xtitle(Years around MW increase event, size(small)) xlabel(-3(1)5, labsize(vsmall)) ///
ytitle("Change in" "log employment rate", size(small)) legend(off) ///
yline(0) ylabel(-0.06(0.03)0.12, labsize(vsmall)) title(E. Log Employment Rate (MSCZ pairs sample), size(small)) ///
name(es_emp_mscz, replace)

frame bcpfig_learn75: twoway (line est1 eventtime, lcolor(blue*0.5) lpattern(solid)) ///
(rcap est2 est3 eventtime, lcolor(blue*0.5) lpattern(dash)), ///
xtitle(Years around MW increase event, size(small)) xlabel(-3(1)5, labsize(vsmall)) ///
ytitle("Change in" "log average weekly earnings", size(small)) legend(off) ///
yline(0) ylabel(-0.06(0.03)0.12, labsize(vsmall)) title(D. Log Earnings (BC pairs sample), size(small)) ///
name(es_earn_bcp, replace)

frame bcpfig_lepop75: twoway (line est1 eventtime, lcolor(blue*0.5) lpattern(solid)) ///
(rcap est2 est3 eventtime, lcolor(blue*0.5) lpattern(dash)), ///
xtitle(Years around MW increase event, size(small)) xlabel(-3(1)5, labsize(vsmall)) ///
ytitle("Change in" "log employment rate", size(small)) legend(off) ///
yline(0) ylabel(-0.06(0.03)0.12, labsize(vsmall)) title(F. Log Employment Rate (BC pairs sample), size(small)) ///
name(es_emp_bcp, replace)

graph combine es_mw_mscz es_mw_bcp es_earn_mscz es_earn_bcp es_emp_mscz es_emp_bcp, rows(3) ysize(8) xsize(7)

graph export "$figures/Figure 2.pdf", replace


* Trend figures
* Regressions

frame drop *learn75 *lemp75 *lepop75 *lmw

local f = 1
foreach frame in msczesfig2 bcpfig2 {
	frame change `frame'
	local a = "pair_id_num##year"
	foreach var in lepop75 learn75 lmw {
		
		replace `var'_dif9 = . if year <= 2001
		replace `var'_dif8 = . if year <= 2000
		
		forvalues i = 1/17 {
			reghdfe `var'_dif`i' event_combined if (event_combined == 1 | clean_control == 1) ///
			, a(`a') cluster(statefips)
			
			if `i' == 1 {
				matrix `frame'_`var' = (r(table)[1,1], r(table)[5,1],r(table)[6,1])
			}
			
			else {
				matrix `frame'_`var'`i' = (r(table)[1,1], r(table)[5,1],r(table)[6,1])
				matrix `frame'_`var' = (`frame'_`var' \ `frame'_`var'`i')
			}
		}
		
		frame create `frame'_`var'
		frame change `frame'_`var'
		svmat `frame'_`var',names(est)
		
		foreach v in est2 est3 {
			replace `v' = 0 if mi(`v')
		}
		
		insobs 1, a(9)
		
		gen eventtime = _n - 14
		frame change `frame'
	}
local ++f
}


frame msczesfig2_learn75 {

	local last_90s = est1[9]
	local first_event = est1[11]
		
	twoway (line est1 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(line est1 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(scatteri `last_90s' -5 `first_event' -3, recast(line) lcolor(blue*0.25) lpattern(shortdash)), ///
	text(-0.14 -9 "Years in 1990s", color(blue*0.25) size(small)) ///
	text(-0.16 -9 "(Extended pre-period)", color(blue*0.25) size(small)) ///
	text(-0.14 0.5 "Years around MW increase event", color(blue*0.5) size(small)) ///
	text(-0.16 0.5 "(Standard event window)", color(blue*0.5) size(small)) ///
	xtitle(" ") xlabel(-13 "1990" -11 "1992" -9 "1994" -7 "1996" -5 "1998" -3(1)4, labsize(vsmall))  ///
	ytitle("Change in" "log average weekly earnings", size(small)) legend(off) ///
	yline(0) ylabel(-0.06(0.03)0.15, labsize(vsmall)) title(C. Log Earnings (MSCZ pairs sample), size(small)) ///
	name(es_earn_mscz, replace)
}

frame msczesfig2_lepop75 {

	local last_90s = est1[9]
	local first_event = est1[11]
		
	twoway (line est1 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(line est1 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(scatteri `last_90s' -5 `first_event' -3, recast(line) lcolor(blue*0.25) lpattern(shortdash)), ///
	text(-0.14 -9 "Years in 1990s", color(blue*0.25) size(small)) ///
	text(-0.16 -9 "(Extended pre-period)", color(blue*0.25) size(small)) ///
	text(-0.14 0.5 "Years around MW increase event", color(blue*0.5) size(small)) ///
	text(-0.16 0.5 "(Standard event window)", color(blue*0.5) size(small)) ///
	xtitle(" ") xlabel(-13 "1990" -11 "1992" -9 "1994" -7 "1996" -5 "1998" -3(1)4, labsize(vsmall))  ///
	ytitle("Change in" "log employment rate", size(small)) legend(off) ///
	yline(0) ylabel(-0.06(0.03)0.15, labsize(vsmall)) title(E. Log Employment Rate (MSCZ pairs sample), size(small)) ///
	name(es_emp_mscz, replace)
}

frame bcpfig2_learn75 {

	local last_90s = est1[9]
	local first_event = est1[11]
		
	twoway (line est1 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(line est1 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(scatteri `last_90s' -5 `first_event' -3, recast(line) lcolor(blue*0.25) lpattern(shortdash)), ///
	text(-0.14 -9 "Years in 1990s", color(blue*0.25) size(small)) ///
	text(-0.16 -9 "(Extended pre-period)", color(blue*0.25) size(small)) ///
	text(-0.14 0.5 "Years around MW increase event", color(blue*0.5) size(small)) ///
	text(-0.16 0.5 "(Standard event window)", color(blue*0.5) size(small)) ///
	xtitle(" ") xlabel(-13 "1990" -11 "1992" -9 "1994" -7 "1996" -5 "1998" -3(1)4, labsize(vsmall))  ///
	ytitle("Change in" "log average weekly earnings", size(small)) legend(off) ///
	yline(0) ylabel(-0.06(0.03)0.15, labsize(vsmall)) title(D. Log Earnings (BC pairs sample), size(small)) ///
	name(es_earn_bcp, replace)
}

frame bcpfig2_lepop75 {

	local last_90s = est1[9]
	local first_event = est1[11]
		
	twoway (line est1 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(line est1 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(scatteri `last_90s' -5 `first_event' -3, recast(line) lcolor(blue*0.25) lpattern(shortdash)), ///
	text(-0.14 -9 "Years in 1990s", color(blue*0.25) size(small)) ///
	text(-0.16 -9 "(Extended pre-period)", color(blue*0.25) size(small)) ///
	text(-0.14 0.5 "Years around MW increase event", color(blue*0.5) size(small)) ///
	text(-0.16 0.5 "(Standard event window)", color(blue*0.5) size(small)) ///
	xtitle(" ") xlabel(-13 "1990" -11 "1992" -9 "1994" -7 "1996" -5 "1998" -3(1)4, labsize(vsmall))  ///
	ytitle("Change in" "log employment rate", size(small)) legend(off) ///
	yline(0) ylabel(-0.06(0.03)0.15, labsize(vsmall)) title(F. Log Employment Rate (BC pairs sample), size(small)) ///
	name(es_emp_bcp, replace)
}


frame msczesfig2_lmw {

	local last_90s = est1[9]
	local first_event = est1[11]
		
	twoway (line est1 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(line est1 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(scatteri `last_90s' -5 `first_event' -3, recast(line) lcolor(blue*0.25) lpattern(shortdash)), ///
	text(-0.18 -9 "Years in 1990s", color(blue*0.25) size(small)) ///
	text(-0.22 -9 "(Extended pre-period)", color(blue*0.25) size(small)) ///
	text(-0.18 0.5 "Years around MW increase event", color(blue*0.5) size(small)) ///
	text(-0.22 0.5 "(Standard event window)", color(blue*0.5) size(small)) ///
	xtitle(" ") xlabel(-13 "1990" -11 "1992" -9 "1994" -7 "1996" -5 "1998" -3(1)4, labsize(vsmall))  ///
	ytitle("Change in" "log average weekly earnings", size(small)) legend(off) ///
	yline(0) ylabel(-0.05(0.05)0.30, labsize(vsmall)) title(A. Log Minimum Wage (MSCZ pairs sample), size(small)) ///
	name(es_mw_mscz, replace)
}

frame bcpfig2_lmw {

	local last_90s = est1[9]
	local first_event = est1[11]
		
	twoway (line est1 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(line est1 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime>=-3, lcolor(blue*0.5) lpattern(solid)) ///
	(rcap est2 est3 eventtime if eventtime<-3, lcolor(blue*0.25) lpattern(solid)) ///
	(scatteri `last_90s' -5 `first_event' -3, recast(line) lcolor(blue*0.25) lpattern(shortdash)), ///
	text(-0.18 -9 "Years in 1990s", color(blue*0.25) size(small)) ///
	text(-0.22 -9 "(Extended pre-period)", color(blue*0.25) size(small)) ///
	text(-0.18 0.5 "Years around MW increase event", color(blue*0.5) size(small)) ///
	text(-0.22 0.5 "(Standard event window)", color(blue*0.5) size(small)) ///
	xtitle(" ") xlabel(-13 "1990" -11 "1992" -9 "1994" -7 "1996" -5 "1998" -3(1)4, labsize(vsmall))  ///
	ytitle("Change in" "log average weekly earnings", size(small)) legend(off) ///
	yline(0) ylabel(-0.05(0.05)0.30, labsize(vsmall)) title(B. Log Minimum Wage (BC pairs sample), size(small)) ///
	name(es_mw_bcp, replace)
}


graph combine es_mw_mscz es_mw_bcp es_earn_mscz es_earn_bcp es_emp_mscz es_emp_bcp , rows(3) ysize(9) xsize(11)

graph export "$figures/Figure 3.pdf", replace


************************************************
* Robustness checks (change pre-period)
************************************************

foreach frame in msczes_pre2 msczes_pre4 bcpes_pre2 bcpes_pre4 {
	frame `frame' {
		bys pair_id_num year: egen event_total = total(event_combined)
		bys pair_id_num year: egen control_total = total(clean_control)
		
		local a = "pair_id_num##year"
		
		eststo `frame'_earn_uw: reghdfe learn75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lepop75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		eststo `frame'_mwe_uw: ivreghdfe lepop75_dif (max_lmw_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lepop75_dif (learn75_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1), a(`a') cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)
		eststo `frame'_emp_w: reghdfe lepop75_dif event_combined if ///
		(event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)
		eststo `frame'_mwe_w: ivreghdfe lepop75_dif (max_lmw_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lepop75_dif (learn75_dif = event_combined) ///
		if (event_combined == 1 | clean_control == 1) [aw=pop], a(`a') cluster(statefips)
		
		gen flag = e(sample)
		preserve
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
	}
}

************************************************
* Robustness check (change event definition and
* change specification)
************************************************

foreach frame in msczes bcpes {
	
	frame change `frame'_federal
	bys pair_id_num year: egen event_total = total(event_combined)
	bys pair_id_num year: egen control_total = total(clean_control)
	
	eststo `frame'_rob1_earn_uw: reghdfe learn75_dif event_combined if ///
	(event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob1_emp_uw: reghdfe lepop75_dif event_combined if ///
	(event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob1_mwe_uw: ivreghdfe lepop75_dif (max_lmw_dif = event_combined) ///
	if (event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob1_owe_uw: ivreghdfe lepop75_dif (learn75_dif = event_combined) ///
	if (event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	
	
	eststo `frame'_rob1_earn_w: reghdfe learn75_dif event_combined if ///
	(event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob1_emp_w: reghdfe lepop75_dif event_combined if ///
	(event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob1_mwe_w: ivreghdfe lepop75_dif (max_lmw_dif = event_combined) ///
	if (event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob1_owe_w: ivreghdfe lepop75_dif (learn75_dif = event_combined) ///
	if (event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	
	gen flag_rob1 = e(sample)
	preserve
		keep if flag_rob1 == 1
		keep if event_total == 1 & control_total == 1
		duplicates drop statefips year, force
		count if event_combined == 1
		local events_rob1 = r(N)
	restore
	estadd local num_events `events_rob1'
	
	
	frame change `frame'
	bys pair_id_num year: egen event_long_total = total(event_combined_long)
	
	eststo `frame'_rob2_earn_uw: reghdfe learn75_dif event_combined_long if ///
	(event_combined_long == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob2_emp_uw: reghdfe lepop75_dif event_combined_long if ///
	(event_combined_long == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob2_mwe_uw: ivreghdfe lepop75_dif (max_lmw_dif = event_combined_long) ///
	if (event_combined_long == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob2_owe_uw: ivreghdfe lepop75_dif (learn75_dif = event_combined_long) ///
	if (event_combined_long == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	
	eststo `frame'_rob2_earn_w: reghdfe learn75_dif event_combined_long if ///
	(event_combined_long == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob2_emp_w: reghdfe lepop75_dif event_combined_long if ///
	(event_combined_long == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob2_mwe_w: ivreghdfe lepop75_dif (max_lmw_dif = event_combined_long) ///
	if (event_combined_long == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob2_owe_w: ivreghdfe lepop75_dif (learn75_dif = event_combined_long) ///
	if (event_combined_long == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	
	gen flag_rob2 = e(sample)
	preserve
		keep if flag_rob2 == 1
		keep if event_long_total == 1 & control_total == 1
		duplicates drop statefips year, force
		count if event_combined_long == 1
		local events_rob2 = r(N)
	restore
	estadd local num_events `events_rob2'
	
	eststo `frame'_rob3_earn_uw: reghdfe learn75_dif event_combined learn_other_dif lpop_dif if ///
	(event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob3_emp_uw: reghdfe lemp75_dif event_combined lemp_other_dif lpop_dif if ///
	(event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob3_mwe_uw: ivreghdfe lemp75_dif (max_lmw_dif = event_combined) ///
	lemp_other_dif lpop_dif if (event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob3_owe_uw: ivreghdfe lemp75_dif (learn75_dif = event_combined) ///
	lemp_other_dif learn_other_dif lpop_dif if (event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	
	eststo `frame'_rob3_earn_w: reghdfe learn75_dif event_combined learn_other_dif lpop_dif if ///
	(event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob3_emp_w: reghdfe lemp75_dif event_combined lemp_other_dif lpop_dif if ///
	(event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob3_mwe_w: ivreghdfe lemp75_dif (max_lmw_dif = event_combined) ///
	lemp_other_dif lpop_dif if (event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	eststo `frame'_rob3_owe_w: ivreghdfe lemp75_dif (learn75_dif = event_combined) ///
	lemp_other_dif learn_other_dif lpop_dif if (event_combined == 1 | clean_control == 1) [aw=pop], a(pair_id_num##year) cluster(statefips)
	
	gen flag_rob3 = e(sample)
	preserve
		keep if flag_rob3 == 1
		keep if event_total == 1 & control_total == 1
		duplicates drop statefips year, force
		count if event_combined == 1
		local events_rob3 = r(N)
	restore
	estadd local num_events `events_rob3'
	
}

local sterfile es_cdlz_estimates  
estimates describe using "$intermediate/`sterfile'"
forvalues j=1/`r(nestresults)' {
    qui estimates describe using "$intermediate/`sterfile'", number(`j')
    local title `r(title)'
    qui estimates use "$intermediate/`sterfile'", number(`j')
    qui est store `title'
}


esttab msczes_rob1_earn_uw msczes_rob2_earn_uw msczes_cdlz_earn_uw ///
bcpes_rob1_earn_uw bcpes_rob2_earn_uw bcpes_cdlz_earn_uw ///
using "$tables/Table D4.tex", replace booktabs b(3) se(3) ///
mtitles("\shortstack{Federal\\events\\included}" "\shortstack{No fed\\increase in\\pre-period}" ///
"\shortstack{CDLZ events\\+ CDLZ\\controls}" "\shortstack{Federal\\events\\included}" ///
"\shortstack{No fed\\increase in\\pre-period}" "\shortstack{CDLZ events\\+ CDLZ\\controls}") ///
rename(event_combined_long event_combined largetreat event_combined) keep(event_combined) ///
varlabels(event_combined "Log wages") nonote noobs star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
mgroups("MSCZ pairs" "BC pairs", pattern(1 0 0 1 0 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
title(Event study estimates from QCEW data: Robustness to event definitions \label{tab:robust1}) ///
postfoot( ) ///
posthead(\midrule \\ ///
\multicolumn{7}{l}{\textbf{A. Unweighted}} \\ & & & \\)

esttab msczes_rob1_emp_uw msczes_rob2_emp_uw msczes_cdlz_emp_uw ///
bcpes_rob1_emp_uw bcpes_rob2_emp_uw bcpes_cdlz_emp_uw ///
using "$tables/Table D4.tex", append booktabs b(3) se(3) nomtitles ///
rename(event_combined_long event_combined largetreat event_combined) keep(event_combined) ///
varlabels(event_combined "Log employment rate") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_rob1_mwe_uw msczes_rob2_mwe_uw msczes_cdlz_mwe_uw ///
bcpes_rob1_mwe_uw bcpes_rob2_mwe_uw bcpes_cdlz_mwe_uw ///
using "$tables/Table D4.tex", append booktabs b(3) se(3) nomtitles ///
keep(max_lmw_dif) ///
varlabels(max_lmw_dif "MWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_rob1_owe_uw msczes_rob2_owe_uw msczes_cdlz_owe_uw ///
bcpes_rob1_owe_uw bcpes_rob2_owe_uw bcpes_cdlz_owe_uw ///
using "$tables/Table D4.tex", append booktabs b(3) se(3) nomtitles ///
keep(learn75_dif) ///
varlabels(learn75_dif "OWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_rob1_earn_w msczes_rob2_earn_w msczes_cdlz_earn_w ///
bcpes_rob1_earn_w bcpes_rob2_earn_w bcpes_cdlz_earn_w ///
using "$tables/Table D4.tex", append booktabs b(3) se(3) nomtitles ///
rename(event_combined_long event_combined largetreat event_combined) keep(event_combined) ///
varlabels(event_combined "Log wages") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
prehead(\multicolumn{7}{l}{\textbf{B. Weighted by population}} ///
\\ & & & \\) postfoot( ) posthead( )

esttab msczes_rob1_emp_w msczes_rob2_emp_w msczes_cdlz_emp_w ///
bcpes_rob1_emp_w bcpes_rob2_emp_w bcpes_cdlz_emp_w ///
using "$tables/Table D4.tex", append booktabs b(3) se(3) nomtitles ///
rename(event_combined_long event_combined largetreat event_combined) keep(event_combined) ///
varlabels(event_combined "Log employment rate") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_rob1_mwe_w msczes_rob2_mwe_w msczes_cdlz_mwe_w ///
bcpes_rob1_mwe_w bcpes_rob2_mwe_w bcpes_cdlz_mwe_w ///
using "$tables/Table D4.tex", append booktabs b(3) se(3) nomtitles ///
keep(max_lmw_dif) ///
varlabels(max_lmw_dif "MWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_rob1_owe_w msczes_rob2_owe_w msczes_cdlz_owe_w ///
bcpes_rob1_owe_w bcpes_rob2_owe_w bcpes_cdlz_owe_w ///
using "$tables/Table D4.tex", append booktabs b(3) se(3) nomtitles ///
keep(learn75_dif) ///
varlabels(learn75_dif "OWE") nonote nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
stats(N num_events, ///
labels("N" "Events evaluated") fmt(%9.0fc)) ///
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
\textit{Notes:} This table checks robustness of our baseline event study estimates ///
in Table \ref{tab:es1} by changing event definitions. Columns 1-3 report estimates ///
for MSCZ pairs, while Columns 4-6 have results for BC pairs. Columns 1 and 4 include ///
federal increase events, as discussed in sub-section \ref{sec:app_fed_inc}. Columns ///
2 and 5 remove events that have a federal increase up to three years prior. Finally, ///
Columns 3 and 6 use the uncombined event definitions from \cite{cengiz2019effect}, also using their ///
specification to control for other events in the event window (see sub-section \ref{sec:app_CDLZ_events}). ///
Outcomes are defined similarly to Table \ref{tab:es1}. ///
Standard errors, reported in parentheses, are clustered at the ///
state level. Stars indicate statistical significance as follows: \sym{*} \(p<0.10\), ///
\sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
) ///
substitute("\_" "_")


esttab msczes_pre2_earn_uw msczes_pre4_earn_uw msczes_rob3_earn_uw bcpes_pre2_earn_uw ///
bcpes_pre4_earn_uw bcpes_rob3_earn_uw ///
using "$tables/Table D5.tex", replace booktabs b(3) se(3) ///
mtitles("\shortstack{Clean controls:\\No increase\\2 years prior}" "\shortstack{Clean controls:\\No increase\\4 years prior}" ///
"\shortstack{Outcome\\is log\\employment}" "\shortstack{Clean controls:\\No increase\\2 years prior}" ///
"\shortstack{Clean controls:\\No increase\\4 years prior}" "\shortstack{Outcome\\is log\\employment}") ///
keep(event_combined) ///
varlabels(event_combined "Log wages") nonote noobs star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
mgroups("MSCZ pairs" "BC pairs", pattern(1 0 0 1 0 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
title(Event study estimates from QCEW data: Robustness to control sets and covariates \label{tab:robust2}) ///
postfoot( ) ///
posthead(\midrule \\ ///
\multicolumn{7}{l}{\textbf{A. Unweighted}} \\ & & & \\)

esttab msczes_pre2_emp_uw msczes_pre4_emp_uw msczes_rob3_emp_uw bcpes_pre2_emp_uw ///
bcpes_pre4_emp_uw bcpes_rob3_emp_uw ///
using "$tables/Table D5.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "Log employment (rate)") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_pre2_mwe_uw msczes_pre4_mwe_uw msczes_rob3_mwe_uw bcpes_pre2_mwe_uw ///
bcpes_pre4_mwe_uw bcpes_rob3_mwe_uw ///
using "$tables/Table D5.tex", append booktabs b(3) se(3) nomtitles ///
keep(max_lmw_dif) ///
varlabels(max_lmw_dif "MWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_pre2_owe_uw msczes_pre4_owe_uw msczes_rob3_owe_uw bcpes_pre2_owe_uw ///
bcpes_pre4_owe_uw bcpes_rob3_owe_uw ///
using "$tables/Table D5.tex", append booktabs b(3) se(3) nomtitles ///
keep(learn75_dif) ///
varlabels(learn75_dif "OWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_pre2_earn_w msczes_pre4_earn_w msczes_rob3_earn_w bcpes_pre2_earn_w ///
bcpes_pre4_earn_w bcpes_rob3_earn_w ///
using "$tables/Table D5.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "Log wages") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
prehead(\multicolumn{7}{l}{\textbf{B. Weighted by population}} ///
\\ & & & \\) postfoot( ) posthead( )

esttab msczes_pre2_emp_w msczes_pre4_emp_w msczes_rob3_emp_w bcpes_pre2_emp_w ///
bcpes_pre4_emp_w bcpes_rob3_emp_w ///
using "$tables/Table D5.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "Log employment (rate)") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_pre2_mwe_w msczes_pre4_mwe_w msczes_rob3_mwe_w bcpes_pre2_mwe_w ///
bcpes_pre4_mwe_w bcpes_rob3_mwe_w ///
using "$tables/Table D5.tex", append booktabs b(3) se(3) nomtitles ///
keep(max_lmw_dif) ///
varlabels(max_lmw_dif "MWE") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_pre2_owe_w msczes_pre4_owe_w msczes_rob3_owe_w bcpes_pre2_owe_w ///
bcpes_pre4_owe_w bcpes_rob3_owe_w ///
using "$tables/Table D5.tex", append booktabs b(3) se(3) nomtitles ///
keep(learn75_dif) ///
varlabels(learn75_dif "OWE") nonote nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
stats(N num_events, ///
labels("N" "Events evaluated") fmt(%9.0fc)) ///
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
\textit{Notes:} This table checks robustness of our baseline event study estimates ///
in Table \ref{tab:es1} by changing covariates or how control areas are defined. Columns 1-3 report estimates ///
for MSCZ pairs, while Columns 4-6 have results for BC pairs. Columns 1 and 4 (2 and 5) require ///
controls areas to have no state minimum wage increases 2 (4) years prior, instead of the baseline 3. ///
Columns 3 and 6 change the dependent variable from log employment \textit{rate} ///
to log employment. They also add controls for log population, and log employment ///
and log earnings in non-restaurant sectors. This is similar to JNR's TWFE specification. ///
However, keeping in line with the specification in the baseline event-study equation ///
\ref{eq:ES}, our controls are also in differenced form. ///
Outcomes, such as MWE and OWE are defined similarly as Table \ref{tab:es1}. ///
Standard errors, reported in parentheses, are clustered at the ///
state level. Stars indicate statistical significance as follows: \sym{*} \(p<0.10\), ///
\sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
) ///
substitute("\_" "_")

************************************************
* Cohorts by post-period
************************************************

estimates clear
local f = 1
foreach frame in msczes bcp {
	frame change `frame'_cohorts
	bys pair_id_num year: egen event_total = total(event_combined)
	bys pair_id_num year: egen control_total = total(clean_control)
	foreach var in lepop75 learn75 {
		eststo `frame'_`var'_full_avg: reghdfe `var'_dif event_combined if ///
		(event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
		
		forvalues k = 4/9 {
			eststo `frame'_`var'_full_`k': reghdfe `var'_dif`k' event_combined if ///
			(event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
		}
		
		forvalues i = 1/6 {
			local m = `i' + 3
			eststo `frame'_`var'_`i'_avg: reghdfe `var'_dif`m'_cum event_combined if ///
			(event_combined == 1 | clean_control == 1) & post_period_cohort >= `i', a(pair_id_num##year) cluster(statefips)
			forvalues j = 4/9 {
				if `j' <= `m' {
					eststo `frame'_`var'_`i'_`j': reghdfe `var'_dif`j' event_combined if ///
					(event_combined == 1 | clean_control == 1) & post_period_cohort >= `i', a(pair_id_num##year) cluster(statefips)
				}
			}
		}
	}
	
	eststo `frame'_owe_full: ivreghdfe lepop75_dif (learn75_dif = event_combined) if ///
	(event_combined == 1 | clean_control == 1), a(pair_id_num##year) cluster(statefips)
	
	preserve
			gen flag = e(sample)
			keep if flag == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events = r(N)
		restore
		estadd local num_events `events'
	
	forvalues i = 1/6 {
		local m = `i' + 3
		eststo `frame'_owe_`i': ivreghdfe lepop75_dif`m'_cum (learn75_dif`m'_cum = event_combined) if ///
		(event_combined == 1 | clean_control == 1) & post_period_cohort >= `i', a(pair_id_num##year) cluster(statefips)
		
		gen flag`i' = e(sample)
		preserve
			keep if flag`i' == 1
			keep if event_total == 1 & control_total == 1
			duplicates drop statefips year, force
			count if event_combined == 1
			local events`i' = r(N)
		restore
		estadd local num_events `events`i''
	}
	
local ++ f
}



eststo placeholder: reg lepop75 event_combined_long

esttab msczes_learn75_full_4 msczes_learn75_1_4 msczes_learn75_2_4 msczes_learn75_3_4 ///
msczes_learn75_4_4 msczes_learn75_5_4 msczes_learn75_6_4 ///
using "$tables/Table D6.tex", replace booktabs b(3) se(3) ///
mtitles(" " "\geq 1" "\geq 2" "\geq 3" "\geq 4" "\geq 5" "= 6") ///
mgroups("Full sample" "Balanced sample - different post-period lengths", pattern(1 1 0 0 0 0 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
keep(event_combined) ///
varlabels(event_combined "k = 0") nonote noobs star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
title(Dynamic event study estimates for cohorts with different post-periods - MSCZ pairs \label{tab:post_period_cohorts_alt_mscz}) ///
postfoot( ) ///
posthead(\midrule \\ ///
\multicolumn{8}{l}{\textbf{A. Log earnings}} \\ & & & \\) ///
substitute("\_" "_")

esttab msczes_learn75_full_5 placeholder msczes_learn75_2_5 msczes_learn75_3_5 ///
msczes_learn75_4_5 msczes_learn75_5_5 msczes_learn75_6_5 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 1") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_learn75_full_6 placeholder placeholder msczes_learn75_3_6 ///
msczes_learn75_4_6 msczes_learn75_5_6 msczes_learn75_6_6 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 2") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_learn75_full_7 placeholder placeholder placeholder ///
msczes_learn75_4_7 msczes_learn75_5_7 msczes_learn75_6_7 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 3") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_learn75_full_8 placeholder placeholder placeholder ///
placeholder msczes_learn75_5_8 msczes_learn75_6_8 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 4") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_learn75_full_9 placeholder placeholder placeholder ///
placeholder placeholder msczes_learn75_6_9 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 5") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_learn75_full_avg msczes_learn75_1_avg msczes_learn75_2_avg msczes_learn75_3_avg ///
msczes_learn75_4_avg msczes_learn75_5_avg msczes_learn75_6_avg ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "Post-averaged effect") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( ) ///

esttab msczes_lepop75_full_4 msczes_lepop75_1_4 msczes_lepop75_2_4 msczes_lepop75_3_4 ///
msczes_lepop75_4_4 msczes_lepop75_5_4 msczes_lepop75_6_4 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 0") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
prehead(\multicolumn{8}{l}{\textbf{B. Log employment rate}} ///
\\ & & & \\) postfoot( ) posthead( )

esttab msczes_lepop75_full_5 placeholder msczes_lepop75_2_5 msczes_lepop75_3_5 ///
msczes_lepop75_4_5 msczes_lepop75_5_5 msczes_lepop75_6_5 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 1") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_lepop75_full_6 placeholder placeholder msczes_lepop75_3_6 ///
msczes_lepop75_4_6 msczes_lepop75_5_6 msczes_lepop75_6_6 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 2") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_lepop75_full_7 placeholder placeholder placeholder ///
msczes_lepop75_4_7 msczes_lepop75_5_7 msczes_lepop75_6_7 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 3") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_lepop75_full_8 placeholder placeholder placeholder ///
placeholder msczes_lepop75_5_8 msczes_lepop75_6_8 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 4") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_lepop75_full_9 placeholder placeholder placeholder ///
placeholder placeholder msczes_lepop75_6_9 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 5") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab msczes_lepop75_full_avg msczes_lepop75_1_avg msczes_lepop75_2_avg msczes_lepop75_3_avg ///
msczes_lepop75_4_avg msczes_lepop75_5_avg msczes_lepop75_6_avg ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "Post-averaged effect") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( ) 

esttab msczes_owe_full msczes_owe_1 msczes_owe_2 msczes_owe_3 msczes_owe_4 msczes_owe_5 ///
msczes_owe_6 ///
using "$tables/Table D6.tex", append booktabs b(3) se(3) nomtitles ///
rename(learn75_dif4_cum learn75_dif learn75_dif5_cum learn75_dif learn75_dif6_cum learn75_dif ///
learn75_dif7_cum learn75_dif learn75_dif8_cum learn75_dif learn75_dif9_cum learn75_dif) ///
keep(learn75_dif) ///
varlabels(learn75_dif "\textbf{OWE}") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
stats(N num_events, ///
labels("\shortstack{N\\(for average effect)}" "Events evaluated") fmt(%9.0fc)) ///
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
\textit{Notes:} Coefficients are from specification in Equation \ref{eq:ES_dynamic} ///
estimated using MSCZ pairs data from the QCEW. \textit{k} in the row headers refers to years from the event. ///
Column 1 uses the full sample of events, while the other columns restrict the regression ///
to balanced samples based on length of post-period. For example, Column 4 only calculates ///
an effect for 3 post-periods using events that have at least 3 post-periods. Thus, all estimates ///
for any particular column come from the same events. The OWE reported in the last row ///
is the own-wage elasticity for the post-averaged effect. ///
Standard errors, reported in parentheses, are clustered at the ///
state level. Stars indicate statistical significance as follows: \sym{*} \(p<0.10\), ///
\sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
) ///
substitute("\_" "_")



eststo placeholder: reg lepop75 event_combined_long
esttab bcp_learn75_full_4 bcp_learn75_1_4 bcp_learn75_2_4 bcp_learn75_3_4 ///
bcp_learn75_4_4 bcp_learn75_5_4 bcp_learn75_6_4 ///
using "$tables/Table D7.tex", replace booktabs b(3) se(3) ///
mtitles(" " "\geq 1" "\geq 2" "\geq 3" "\geq 4" "\geq 5" "= 6") ///
mgroups("Full sample" "Balanced sample - different post-period lengths", pattern(1 1 0 0 0 0 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
keep(event_combined) ///
varlabels(event_combined "k = 0") nonote noobs star(* 0.1 ** 0.05 *** 0.01) width(\hsize) ///
title(Dynamic event study estimates for cohorts with different post-periods - BC pairs \label{tab:post_period_cohorts_alt_bcp}) ///
postfoot( ) ///
posthead(\midrule \\ ///
\multicolumn{8}{l}{\textbf{A. Log earnings}} \\ & & & \\) ///
substitute("\_" "_")

esttab bcp_learn75_full_5 placeholder bcp_learn75_2_5 bcp_learn75_3_5 ///
bcp_learn75_4_5 bcp_learn75_5_5 bcp_learn75_6_5 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 1") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_learn75_full_6 placeholder placeholder bcp_learn75_3_6 ///
bcp_learn75_4_6 bcp_learn75_5_6 bcp_learn75_6_6 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 2") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_learn75_full_7 placeholder placeholder placeholder ///
bcp_learn75_4_7 bcp_learn75_5_7 bcp_learn75_6_7 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 3") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_learn75_full_8 placeholder placeholder placeholder ///
placeholder bcp_learn75_5_8 bcp_learn75_6_8 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 4") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_learn75_full_9 placeholder placeholder placeholder ///
placeholder placeholder bcp_learn75_6_9 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 5") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_learn75_full_avg bcp_learn75_1_avg bcp_learn75_2_avg bcp_learn75_3_avg ///
bcp_learn75_4_avg bcp_learn75_5_avg bcp_learn75_6_avg ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "Post-averaged effect") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( ) ///

esttab bcp_lepop75_full_4 bcp_lepop75_1_4 bcp_lepop75_2_4 bcp_lepop75_3_4 ///
bcp_lepop75_4_4 bcp_lepop75_5_4 bcp_lepop75_6_4 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 0") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
prehead(\multicolumn{8}{l}{\textbf{B. Log employment rate}} ///
\\ & & & \\) postfoot( ) posthead( )

esttab bcp_lepop75_full_5 placeholder bcp_lepop75_2_5 bcp_lepop75_3_5 ///
bcp_lepop75_4_5 bcp_lepop75_5_5 bcp_lepop75_6_5 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 1") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_lepop75_full_6 placeholder placeholder bcp_lepop75_3_6 ///
bcp_lepop75_4_6 bcp_lepop75_5_6 bcp_lepop75_6_6 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 2") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_lepop75_full_7 placeholder placeholder placeholder ///
bcp_lepop75_4_7 bcp_lepop75_5_7 bcp_lepop75_6_7 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 3") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_lepop75_full_8 placeholder placeholder placeholder ///
placeholder bcp_lepop75_5_8 bcp_lepop75_6_8 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 4") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_lepop75_full_9 placeholder placeholder placeholder ///
placeholder placeholder bcp_lepop75_6_9 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "k = 5") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab bcp_lepop75_full_avg bcp_lepop75_1_avg bcp_lepop75_2_avg bcp_lepop75_3_avg ///
bcp_lepop75_4_avg bcp_lepop75_5_avg bcp_lepop75_6_avg ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
keep(event_combined) ///
varlabels(event_combined "Post-averaged effect") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( ) 

esttab bcp_owe_full bcp_owe_1 bcp_owe_2 bcp_owe_3 bcp_owe_4 bcp_owe_5 ///
bcp_owe_6 ///
using "$tables/Table D7.tex", append booktabs b(3) se(3) nomtitles ///
rename(learn75_dif4_cum learn75_dif learn75_dif5_cum learn75_dif learn75_dif6_cum learn75_dif ///
learn75_dif7_cum learn75_dif learn75_dif8_cum learn75_dif learn75_dif9_cum learn75_dif) ///
keep(learn75_dif) ///
varlabels(learn75_dif "\textbf{OWE}") nonote noobs nonum star(* 0.1 ** 0.05 *** 0.01) ///
width(\hsize) ///
stats(N num_events, ///
labels("\shortstack{N\\(for average effect)}" "Events evaluated") fmt(%9.0fc)) ///
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
\textit{Notes:} Coefficients are from specification in Equation \ref{eq:ES_dynamic} ///
estimated using BC pairs data from the QCEW. \textit{k} in the row headers refers to years from the event. ///
Column 1 uses the full sample of events, while the other columns restrict the regression ///
to balanced samples based on length of post-period. For example, Column 4 only calculates ///
an effect for 3 post-periods using events that have at least 3 post-periods. Thus, all estimates ///
for any particular column come from the same events. The OWE reported in the last row ///
is the own-wage elasticity for the post-averaged effect. ///
Standard errors, reported in parentheses, are clustered at the ///
state level. Stars indicate statistical significance as follows: \sym{*} \(p<0.10\), ///
\sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
) ///
substitute("\_" "_")




***************************************************
* Figure showing events
***************************************************

frame change events_fig

twoway (scatter stateindex year if mw_increase_fig == 1, msymbol(s) mlab(state_abb) ///
mlabsize(tiny) mlabcolor(black) mcolor(green*0.2) mlabgap(-2.9)) ///
(scatter stateindex year if mw_increase_fig == 2, msymbol(d) mlab(state_abb) mlabsize(tiny) ///
mlabcolor(black) mcolor(orange*0.2) mlabgap(-2.9)) ///
(scatter stateindex year if mw_increase_fig ==3, msymbol(t) mlab(state_abb) mlabsize(tiny) ///
mlabcolor(black) mcolor(purple*0.2) mlabgap(-2.9)) ///
(scatter stateindex year if mw_increase_fig == 4, msymbol(o) mlab(state_abb) mlabsize(tiny) ///
mcolor(blue) mlabcolor(black) mlabgap(-2.9)) ///
(scatter stateindex year if mw_increase_fig == 5, msymbol(oh) mlab(state_abb) mlabsize(tiny) ///
mcolor(blue*0.3) mlabcolor(black) mlabgap(-2.9)) ///
, xlab(1990(2)2020, labsize(vsmall) nogrid) xtitle("") ///
xline(1990 1991 1996 1997 2007 2008 2009, lpattern(1) lcolor(gs12)) ///
graphregion(color(white)) yscale(off) plotregion(color(white)) ylab(,nogrid) ///
legend(pos(6) order(1 2 4 5 3) label(1 "Federal MW increase") ///
label(2 "Small state MW increase (<5% or <$0.25)") ///
label(4 "Prominent state MW increase - marking start of 45 events studied") ///
label(5 "State MW increase combined with 45 events") ///
label(3 "Other prominent state MW increases (not evaluated)") rows(2) cols(3) ///
size(vsmall)) ysize(4) xsize(6.5)

graph export "$figures/Figure D1.pdf", replace

***************************************************
* Create tables for event details
***************************************************

frame copy state cohorts
frame change cohorts

sort year statefips, stable

bys year: egen controls_num = total(clean_control)

gen post_period = .
replace post_period = 6 if inrange(year,1998,2001) ///
| inrange(year,2010,2014)
replace post_period = 5 if inlist(year,2002,2015)
replace post_period = 4 if inlist(year,1992,2003,2016)
replace post_period = 3 if inlist(year,1993,2004,2017)
replace post_period = 2 if inlist(year,1994,2005,2018)
replace post_period = 1 if inlist(year,1995,2006,2019)

keep if event_combined == 1
keep year statefips event_combined controls_num max_lmw_dif post_period
foreach var in controls_num max_lmw_dif post_period {
	sum `var'
	local `var'_mean = `r(mean)'
}

local controls_num_mean: disp %4.1f `controls_num_mean'
local post_period_mean: disp %4.1f `post_period_mean'
local max_lmw_dif_mean: disp %04.3f `max_lmw_dif_mean'

sum event_combined
local event_combined_count = `r(N)'

collapse (mean) max_lmw_dif controls_num post_period (count) event_combined, by(year)
gen max_lmw_dif_round = round(max_lmw_dif,0.001)
format max_lmw_dif_round %04.3f
drop max_lmw_dif
rename max_lmw_dif_round max_lmw_dif

order year event_combined post_period controls_num max_lmw_dif
mkmat event_combined post_period controls_num max_lmw_dif, matrix(event_details) rownames(year)

matrix locals = (`event_combined_count', `post_period_mean', `controls_num_mean', `max_lmw_dif_mean')
matrix rownames locals = Overall
matrix event_details = (event_details \ locals)

esttab matrix(event_details) using "$tables/Table D2.tex", replace booktabs ///
collabels("\shortstack{Number of\\events}" ///
"\shortstack{Post period\\length(years)}" "\shortstack{No. of clean\\control states}" "\shortstack{Mean increase\\in log MW}") ///
title("Details by cohort of 45 events used in event study analysis \label{tab:eventdetails}") mlabels(none) ///
prehead(\begin{table}[htbp]\centering ///
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} ///
\caption{Details for the 45 combined minimum wage events, by year of the initial increase \label{tab:eventdetails}} ///
\begin{tabular*}{\hsize} ///
{@{\hskip\tabcolsep\extracolsep\fill}l*{4}{c}} ///
\toprule) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
This table provides information by cohort on the 45 state-level events used in the event-study ///
analysis. The 45 events are defined as per state minimum wage changes. Availability of data and ///
variation across county/commuting zone pairs dictate which events are actually used in different ///
specifications. The first column reports the number of events in that cohort/year. The ///
second column gives the length of the post-period for that cohort in years. ///
Post-periods are a maximum of 6 years unless interrupted by a federal MW increase ///
year or end-of-sample. ///
The third column reports number of states that serve as clean controls for the ///
cohort - a clean control needs to have no state MW increase in the three years ///
before the cohort year, and also no state MW increase in the relevant post-period. ///
Finally, the last column reports the average log MW increase (average of the difference between log MW in ///
the last year of the post-period and the log MW in year \textit{t-1}, where \textit{t} is the event year) ///
across all events in a cohort. The last row gives the total number of events and ///
means \textit{by event} (not by cohort) of post-period length, clean control states, ///
and log MW increase. ///
\end{footnotesize}}} ///
\end{table} ///
)




************************************************
* Table showing events evaluated
************************************************

frame copy state events_increases
frame change events_increases

* creating mw increase types we used to create the events figure (Figure A1)

gen mw_increase_type = 0

replace mw_increase_type = 1 if mw>L.mw & mw == fed_mw
replace mw_increase_type = 2 if (mw>L.mw) & ((mw<1.05*L.mw) | (mw<L.mw + 0.25)) & mw>fed_mw
replace mw_increase_type = 3 if mw>=1.05*L.mw & mw>=L.mw + 0.25 & mw>fed_mw
replace mw_increase_type = 4 if event_combined == 1
replace mw_increase_type = 5 if inlist(mw_increase_type,2,3) & ///
~inlist(year,1981,1990,1991,1996,1997,2007,2008,2009) & (L.event_combined == 1 | ///
L2.event_combined == 1 | L3.event_combined == 1 | L4.event_combined == 1 | L5.event_combined == 1)

gen evaluated = mw_increase_type == 5 //5 are mw increases evaluated with our combined events
forvalues i = 1/5 {
	gen f`i'_evaluated = F`i'.evaluated
}
egen evaluated_num = rowtotal(f1_evaluated f2_evaluated f3_evaluated f4_evaluated f5_evaluated)
keep if mw_increase_type == 4
replace evaluated_num = evaluated_num + 1 //now evaluated_num gives us number of events evaluated with each combined event (along with the main event itself)
keep statefips year evaluated_num

tempfile events_increases
save `events_increases'

* now seeing how many events are used in which dataset which dataset


local j = 1
foreach f in state msczes bcpes {
	
	frame copy `f' `f'_events
	frame change `f'_events
	if `j' == 1 {
		local a = "year"
		bys year: egen event_total = total(event_combined)
	}
	
	else {
		local a = "pair_id_num##year"
	}
	
	
	reghdfe lepop75_dif event_combined if (event_combined == 1 | clean_control == 1) ///
	[aw=pop], a(`a') cluster(statefips)
	cap drop flag
	gen flag = e(sample)
	keep if flag == 1
	if `j' >= 2 {
	distinct pair_id_num
	local `f'_pairs_used = `r(ndistinct)'
	keep if event_total == 1 & control_total == 1
	distinct pair_id_num
	local `f'_pairs_treat_vary = `r(ndistinct)'
	}
	
	else {
		keep if event_total > 0
	}
	duplicates drop statefips year, force
	keep if event_combined == 1
	merge 1:1 statefips year using `events_increases', assert(2 3) keep(3)
	
	count
	local `f'_combined = `r(N)'
	
	sum evaluated_num, d
	local `f'_total = `r(sum)'
	
	local ++j
}


matrix events_combined = (`state_combined', `msczes_combined', `bcpes_combined')

matrix events_total = (`state_total', `msczes_total', `bcpes_total')

matrix es_pairs_used = J(1,3,.)
matrix es_pairs_used[1,2] = `msczes_pairs_used'
matrix es_pairs_used[1,3] = `bcpes_pairs_used'

matrix es_pairs_treat_vary = J(1,3,.)
matrix es_pairs_treat_vary[1,2] = `msczes_pairs_treat_vary'
matrix es_pairs_treat_vary[1,3] = `bcpes_pairs_treat_vary'

matrix events = (events_combined \ events_total \ es_pairs_used \ es_pairs_treat_vary)

matrix rownames events = "Combined MW increases" "All underlying MW increases" "Pairs in regression" "Pairs with treatment variation"

esttab matrix (events) using "$tables/Table D1.tex", replace booktabs ///
mlabels(none) ///
prehead(\begin{table}[htbp]\centering ///
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} ///
\caption{Number of events evaluated in different event study specifications \label{tab:events}} ///
\begin{tabular*}{\hsize} ///
{@{\hskip\tabcolsep\extracolsep\fill}l*{3}{c}} ///
\toprule) ///
collabels("State" "MSCZ pairs" "BC pairs") ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
Table notes put in separately ///
\end{footnotesize}}} ///
\end{table} ///
)

/*This table shows the number of events evaluated and the number of border county and MSCZ pairs in QCEW baseline event study regressions. These are the regressions in Table \ref{tab:es1}. We report the state sample too to show total number of potential events. The numbers reported are for the full period regressions for each sample. The first row reports the total number of combined events, while the second row gives the number of all MW increases evaluated with the combined events included. The third and fourth rows report the number of commuting zone/county pairs used. Our estimation sample for all years is all units which are either newly treated or a clean control for that particular year. Thus, unit-years which are neither are dropped. Moreover, the Stata command reghdfe, which we use with pair-year fixed effects drops singletons - pair-years where one side is either treated or control, but the other side is neither. Therefore, the pair-years that remain in the regression are those where either 1) one side is treated and the other is a clean control; or 2) both are treated; or 3) both are controls. The total unique number of such pairs (belonging to all three categories) is reported in the third row. However, considering the fixed effects are at the pair-year level, the coefficients are calculated using the pair-years with variation in treatment (only category 1 above). Thus, the final row reports all such pairs. Row 1 in this table, and any table in the paper which shows "events evaluated" reports the number of events using these pairs only.  ///


